<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%
	String pkId = request.getParameter("pkId");
    String tabNm = request.getParameter("tabNm");
	String detailId = request.getParameter("detailId");
 %>
<input type="hidden" id="pkId" value="<%=pkId %>"/>
<input type="hidden" id="tabNm" value="<%=tabNm %>"/>
<input type="hidden" id="detailId" value="<%=detailId %>"/>
<script type="text/javascript">
	var fileGrid = null;
	
	$(function () {
		var _pkId = $("#pkId").val();
		var _tabNm = $("#tabNm").val();
		var _url = '<%=path%>/system/sysulfilesrec/initList.do';
	    $("#ligergrid2").ligerGrid({
	    	usePager: false,
	    	url: _url,
	    	method : 'get',
	    	parms:{
	    		pkId:_pkId,
	    		tabNm:_tabNm
	    	},
	        columns: [
	            { display: '<div class="headCellWrap">文件名<span class="btns">' +
				'<span class="sq-button sq-button-round" onclick="downloadFileByUrl();">' +
				'打包下载</span></span></div>',name:'fileNm', minWidth: 100, enabledSort:true 
	            	
	            },
	            { display: '提交人员', name: 'crtUsrRlNm', width: 200, enabledSort:true },
				{ display: '提交时间', name: 'crtTm',render:renderDate, width: 200, enabledSort:true },
	            getUlFileRecDelColumn()
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        rownumbers:true,
	        onAfterShowData: function () {
	            $( ".gridTip").grid_ligerTip();
	            SetIframe_height ();
	       }
	    });
	    fileGrid = liger.get("ligergrid2");
	    //grid.setHeight(100);
	});
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
	function uploadFileByUrl(_url,_name){
		if(SQ.regs.img.test(_name)){
			//SQ.imgPreview(_url);
         window.__ImgSrc = _url;
         window.__ImgTit = _name;
         window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
		}else{
	        window.open(_url);
		}
    }

    function downloadFileByUrl() {
        var data = fileGrid.getData();
//        var files = [];
		var ids = [];
		for (var i = 0; i < data.length; i++) {
		    var map = {};
//		    map.name = data[i].fileNm;
//		    map.path = data[i].filePath.substring(data[i].filePath.indexOf("attachments"));
//		    files.push(map);
            ids.push(data[i].id);
		}
		var actoinURL = '<%=path%>/system/sysulfilesrec/zipDownloadById.do';
    	var form = $("<form>");
        $('body').append(form);
        form.attr('style','display:none');
        form.attr('target','');
        form.attr('method','post');
        form.attr('action',actoinURL);//下载文件的请求路径
        var input = $('<input>');
        input.attr('type','hidden');
        input.attr('name','ids');
        input.attr('value',JSON.stringify(ids));
        form.append(input);
        form.submit();
    }
	
	function uploadFileDeleteRow(index,id){
		if(!id){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
			return;
		}
		$.ligerDialog.confirm('确定删除吗?', function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{id:id},
				url: '<%=path%>/system/sysulfilesrec/removeById.do',
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 fileGrid.deleteRow(index);
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
	}
	
	function getUlFileRecDelColumn(){
		var detailId = $("#detailId").val();
		if(detailId == '1'){
			return;
		}
		return {	display: '操作',
			        isSort: false,
			        minWidth: 100,
			        render: function (rowdata, rowindex, value){
			        	//判断是不是追加的-只显示未保存到数据库
						
						var h = "";
			        	if(rowdata.audStsCd=="1"){//验证通过不能删除
			        		return "";
			        	}
			            var h='<a class="sq-button-hasicon" href="javascript:uploadFileDeleteRow(';
			            	h+="'"+rowindex+"',";
			            	h+="'"+rowdata.id+"'";
			                h+=')"><i class="sqBtnIco_7"></i>删除</a>'
			            if(null != rowdata.doSthFlag && "1" == rowdata.doSthFlag){//是否只有删除操作：1 是 0 否
							h='<a class="sq-button-hasicon" href="javascript:deleteSelectedRow(';
							h+="'"+rowindex+"','";//行号
							h+=rowdata.ligerIndex+"','"+rowdata.id+"'"+')"><i class="sqBtnIco_7"></i>删除</a>';
						}
			            return h;
			        }
				};
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//刷新附件列表
	function refreshUlFileRecList(){
		fileGrid.reload();
	}
	//刷新附件列表:重新设置
	function refreshUlFileRecListByPkId(_pkId,_tabNm){
		fileGrid.setParm("pkId",_pkId);
		fileGrid.setParm("tabNm",_tabNm);
		fileGrid.reload();
	}
	//删除选中行-不用选中即可删除当前行
	function deleteSelectedRow(index,ligerIndex,id){
		fileGrid = liger.get("ligergrid2");
		fileGrid.deleteRow(index);
		//根据序号设置不同的参数
			upload_result_params.splice(id, 1);
	}
</script>

<div id="ligergrid2" class="sq-grid"></div>